<!DOCTYPE html>
<html lang="zh-cn">
<head>
{include file="public/header" /}
<script type="text/javascript" src="__HOUTAI__/js/ajaxfileupload.js"></script>
</style>
</head>
<body>
<div class="panel admin-panel">
  <div class="body-content">
    <form id="article-form" class="form-x" action="">  
      <div class="form-group">
        <div class="label">
          <label>标题：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" value="" name="title" id="titleid" />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>图片：</label>
        </div>
        <style type="text/css">
          /*a  upload */
        .a-upload {
            padding: 10px 15px;
            line-height: 20px;
            position: relative;
            cursor: pointer;
            color: #888;
            background: #0ae;
            border: 1px solid #ddd;
            border-radius: 4px;
            overflow: hidden;
            display: inline-block;
            *display: inline;
            *zoom: 1
        }

        .a-upload  input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
            filter: alpha(opacity=0);
            cursor: pointer
        }
        .a-upload:hover {
            color: #444;
            background: #eee;
            border-color: #ccc;
            text-decoration: none
        }
        </style>
        <div class="field">
          <input type="text" name="img" class="input tips" style="width:25%; float:left;"  id="thumb" />
          <a href="javascript:;" class="a-upload button bg-blue margin-left"  style="float:left;">
              <input type="file" id="id_photos" name="id_photos" onchange="thumb_onchange(this);">+ 浏览上传
          </a>
          <img src="" id="upimg" style="height: 42px; margin-left: 15px; float: left;">
          <div class="tipss">图片尺寸：220*150</div>
        </div>
      </div>     
      <div class="form-group">
        <div class="label">
          <label>分类标题：</label>
        </div>
        <div class="field">
          <select name="cid" class="input w50" id="options">
            <option value="0">请选择分类</option>
            {volist name="Content" id="vo"}
            <option value="{$vo.id}">{$vo.name_display}</option>
            {/volist}
          </select>
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>标签：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" value="" name="tag" id="tag" />
          <div class="tipss">多个标签用英文逗号（,）隔开</div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>其他属性：</label>
        </div>
        <div class="field" style="padding-top:8px;"> 
          首页 <input id="ishome"  type="checkbox" />
          推荐 <input id="isvouch"  type="checkbox" />
          置顶 <input id="istop"  type="checkbox" /> 
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>描述：</label>
        </div>
        <div class="field">
          <textarea class="input" name="note" id="desc" style=" height:90px;"></textarea>
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>关键字标题：</label>
        </div>
        <div class="field">
          <input type="text" class="input" name="s_title" id="keywords" value="" />
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>作者：</label>
        </div>
        <div class="field">
          <input type="text" class="input" name="author" id="author" value="樱桃" />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>内容：</label>
        </div>
        <div class="field">
          <!-- 加载编辑器的容器 -->
          <script id="content" name="content" type="text/plain"></script>
          <!-- 配置文件 -->
          <script type="text/javascript" src="__BJQ__ueditor/ueditor.config.js"></script>
          <!-- 编辑器源码文件 -->
          <script type="text/javascript" src="__BJQ__ueditor/ueditor.all.js"></script>
          <!-- 实例化编辑器 -->
          <script type="text/javascript">
            var ue= UE.getEditor('content',{initialFrameWidth:'100%',initialFrameHeight:300,});
          </script>
        </div>
      </div>
      <div class="clear"></div>
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-feiji" type="submit"> 提交</button>
        </div>
      </div>
    </form>
  </div>
</div>
<script type="text/javascript">
function thumb_onchange(obj){
  $.ajaxFileUpload({
    url:"{:url('content/uploadimg')}",   //处理图片的脚本路径
    type: 'POST',       //提交的方式
    secureuri :false,   //是否启用安全提交
    fileElementId :'id_photos',     //file控件ID
    dataType : 'Json',  //服务器返回的数据类型 
    success : function (data){
      var data=eval("("+data+")");
      if(data.status)
      {
        // layer.msg(data.msg);
        $("#upimg").attr("src",data.filename);
        $("#thumb").val(data.filename);
        $("#id_photos").val();
      }
      else
      {
        // layer.alert(data.msg);
        alert('格式错误');
      }
    }
  });
};


$(function(){
  $('#article-form').validate({
    rules:{
      title:{
        required:true,
      }
    },
    message:{
      title: {
        required: "请输入标题名称",
      }
    },
    onkeyup: false,
    focusCleanup: true,
    success: "valid",
    submitHandler:function(form){
      var title= $("#titleid").val(),//标题
      tag= $("#tag").val(), //标签
      thumb=$("#thumb").val(),//图片路径
      cateid=$("#options option:selected").val(),//栏目
      desc=$("#desc").val(),//描述
      keywords=$("#keywords").val();//关键字
      var content = ue.getContent();//获取富文本内容
      var author =$("#author").val(); //作者
      if(cateid==0){
        alert('请选择分类');
        return;
      }
      $.ajax({
        type:"POST",
        url:"{:url('content/addajax')}",
        data:{
          'title':title,
          'tag':tag,
          'thumb':thumb,
          'desc':desc,
          'keywords':keywords,
          'content':content,
          'cateid':cateid,
          'author':author,
        },
        success:function(data){
          var data=eval("("+data+")");
          if (data.status) {
            parent.layer.msg("文章添加成功！！！",{icon:1,time:1000,},function(){parent.location.reload();});
          }else{
            parent.layer.msg("文章添加失败！！！",{icon:2,time:1000});
          }

        }
      })
    }
  })
})
</script>
</body>
</html>